<?php
//admin controller
class IndexController extends action{

	private $setup;
	
	public function __Construct() {

		parent::__Construct();
		$this->loadCtl('login','login');
		loginController::chkLogin();
		//chkLogin($this);
		$this->getMsgSetup();
		
	}
	
	function index(){

		$num = $this->setup['msg_num'];
		$data = $this->toPage('msgs', 'p', 'page', $num);

		$this->Template();
		$this->assign('toPage',$data);
		$this->assign('title','留言板管理');
				
		$this->display('index');
	}
	
	function delMsg(){
		$id = intval($_GET['id']);
		//echo $id;
		
		$obj = $this->M('msgs');
		$r = $obj->delete('where id = '.$id);
		if ($r){
			$this->success('Success !','?g=admin');
		}else{
			$this->error('Error !','?g=admin');
		}
	
	}
	
	function saveSetup(){
		$objsetup = $this->M('msgsetup');
		
		$data['msg_badword'] = $_POST[''];
		$data['msg_num'] = $_POST[''];
		//$data['msg_view'] = $_POST[''];
		$data['msg_activate'] = $_POST[''];
		$data['msg_length'] = $_POST[''];
	}
	
	
	private function getMsgSetup(){
		//如果设置配置文件那么读取配置文件。
		//没有配置文件将访问数据库。
		//这里简单的读取数据库。
		$objsetup = $this->M('msgsetup');
		$result = $objsetup->limit('','','limit 0,1');
		$this->setup = $result[0];
		return $result[0];

	}

	
}



